//
//  BottomTableViewCell.m
//  ZYZB
//
//  Created by ENERGY on 2018/6/25.
//  Copyright © 2018年 ENERGY. All rights reserved.
//

#import "InformTableViewCell.h"
#import "LMJScrollTextView2.h"

@interface InformTableViewCell()<LMJScrollTextView2Delegate>
@property (nonatomic, strong)UIButton * informBtn;//图标
@property (nonatomic, strong)UILabel * informLab;//公告内容
@property (nonatomic, strong)UIButton * moreBtn;//更多
@property (nonatomic, strong)LMJScrollTextView2 * scrollTextView;
@end

@implementation InformTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.contentView.backgroundColor = [UIColor whiteColor];
        __weak typeof(self) weakSelf = self;
        UIView * topLineView = [[UIView alloc] init];
        topLineView.backgroundColor = getColor(grayColor);
        [self.contentView addSubview:topLineView];
        [topLineView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.top.right.equalTo(weakSelf);
            make.height.mas_offset(1/WIDTH_6_SCALE);
        }];
        UIView * bottomLineView = [[UIView alloc] init];
        bottomLineView.backgroundColor = getColor(grayColor);
        [self.contentView addSubview:bottomLineView];
        [bottomLineView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.bottom.right.equalTo(weakSelf);
            make.height.mas_offset(1/WIDTH_6_SCALE);
        }];
        [self.scrollTextView startScrollBottomToTopWithNoSpace];
    }return self;
}
#pragma mark - init
-  (UIButton *)informBtn{
    if (!_informBtn) {
        _informBtn = [[UIButton alloc] init];
        [_informBtn setBackgroundColor:[UIColor clearColor]];
        [_informBtn setImage:[UIImage imageNamed:@"sound"] forState:UIControlStateNormal];
    }return _informBtn;
}

-  (UIButton *)moreBtn{
    if (!_moreBtn) {
        _moreBtn = [[UIButton alloc] init];
        [_moreBtn setBackgroundColor:[UIColor clearColor]];
    }return _moreBtn;
}

-  (UILabel *)informLab{
    if (!_informLab) {
        _informLab = [[UILabel alloc] init];
        _informLab.font = DEF_FontSize_14;
        _informLab.textColor = [UIColor blackColor];
        _informLab.textAlignment = NSTextAlignmentLeft;
        _informLab.text = @"端午节放假通知，连休8天!";
    }return _informLab;
}

- (LMJScrollTextView2 *)scrollTextView{
    if (!_scrollTextView) {
        _scrollTextView = [[LMJScrollTextView2 alloc] init];
        _scrollTextView.delegate            = self;
        _scrollTextView.textStayTime        = 2;
        _scrollTextView.scrollAnimationTime = 1;
        _scrollTextView.textColor           = [UIColor blackColor];
        _scrollTextView.textFont            = [UIFont boldSystemFontOfSize:15.f];
        _scrollTextView.textAlignment       = NSTextAlignmentLeft;
        _scrollTextView.touchEnable         = YES;
        _scrollTextView.layer.cornerRadius  = 3;
    }return _scrollTextView;
}

- (void)layoutSubviews{
    [super layoutSubviews];
    int moreBtnW = 25/WIDTH_6_SCALE;
    [self.contentView addSubview:self.informBtn];
    [self.contentView addSubview:self.informLab];
    [self.contentView addSubview:self.moreBtn];
    [self.contentView addSubview:self.scrollTextView];
    self.informBtn.frame = CGRectMake(18/WIDTH_6_SCALE, 0, 18/WIDTH_6_SCALE, self.contentView.height - 33/WIDTH_6_SCALE);
    self.informBtn.centerY = self.contentView.centerY;
    self.scrollTextView.frame = CGRectMake(self.informBtn.right + 18/WIDTH_6_SCALE, 0, SCREEN_WIDTH - self.informBtn.right - 18/WIDTH_6_SCALE - 45/WIDTH_6_SCALE - 15/WIDTH_6_SCALE, self.informBtn.height);
    self.scrollTextView.centerY = self.contentView.centerY;
    self.moreBtn.frame = CGRectMake(SCREEN_WIDTH - 45/WIDTH_6_SCALE, 14/WIDTH_6_SCALE, moreBtnW, 28/WIDTH_6_SCALE);
}

- (void)setModel:(NSArray *)model{
    _model = model;
    self.scrollTextView.textDataArr = model;
}
#pragma mark - LMJScrollTextView2 Delegate
- (void)scrollTextView2:(LMJScrollTextView2 *)scrollTextView currentTextIndex:(NSInteger)index{
    NSLog(@"当前是信息%ld",index);
}
- (void)scrollTextView2:(LMJScrollTextView2 *)scrollTextView clickIndex:(NSInteger)index content:(NSString *)content{
//    NSLog(@"#####点击的是：第%ld条信息 内容：%@",index,content);
    if (self.model.count == 0) {
        return;
    }
}

@end
